var $parentNode = window.parent.document;

function $childNode(name) {
    return window.frames[name]
}

// tooltips
$('.tooltip-demo').tooltip({
    selector: "[data-toggle=tooltip]",
    container: "body"
});

// 使用animation.css修改Bootstrap Modal
$('.modal').appendTo("body");

$("[data-toggle=popover]").popover();

//折叠ibox
$('.collapse-link').click(function () {
    var ibox = $(this).closest('div.ibox');
    var button = $(this).find('i');
    var content = ibox.find('div.ibox-content');
    content.slideToggle(200);
    button.toggleClass('fa-chevron-up').toggleClass('fa-chevron-down');
    ibox.toggleClass('').toggleClass('border-bottom');
    setTimeout(function () {
        ibox.resize();
        ibox.find('[id^=map-]').resize();
    }, 50);
});

//关闭ibox
$('.close-link').click(function () {
    var content = $(this).closest('div.ibox');
    content.remove();
});

//判断当前页面是否在iframe中
if (top == this) {
    var gohome = '<div class="gohome"><a class="animated bounceInUp" href="index.html?v=4.0" title="返回首页"><i class="fa fa-home"></i></a></div>';
    $('body').append(gohome);
}

//animation.css
function animationHover(element, animation) {
    element = $(element);
    element.hover(
        function () {
            element.addClass('animated ' + animation);
        },
        function () {
            //动画完成之前移除class
            window.setTimeout(function () {
                element.removeClass('animated ' + animation);
            }, 2000);
        });
}

//拖动面板
function WinMove() {
    var element = "[class*=col]";
    var handle = ".ibox-title";
    var connect = "[class*=col]";
    $(element).sortable({
            handle: handle,
            connectWith: connect,
            tolerance: 'pointer',
            forcePlaceholderSize: true,
            opacity: 0.8,
        })
        .disableSelection();
};

//全选和取消全选
$('input[name="selectall"]').click(function(){
    //alert(this.checked);
    if($(this).is(':checked')){
        $('input[name="checkBox"]').each(function(){
            //此处如果用attr，会出现第三次失效的情况
            $(this).prop("checked",true);
        });
    }else{
        $('input[name="checkBox"]').each(function(){
            $(this).removeAttr("checked",false);
        });
        //$(this).removeAttr("checked");
    }
});
$('input[name="checkBox"]').click(function(){
    if($('input[name="checkBox"]').length != $('input[name="checkBox"]:checked').length){
        $('input[name="selectall"]').prop("checked",false);
    }else{
        $('input[name="selectall"]').prop("checked",true);
    }
})


//iframe内打开新页面窗口
function open_page(url, title) {
    $(window.parent.document).find('.J_menuTabs .page-tabs-content a').removeClass('active');
    $(window.parent.document).find('.J_menuTabs .page-tabs-content').append('<a href="javascript:;" class="J_menuTab active" data-id="'+url+'">'+title+' <i class="fa fa-times-circle"></i></a>');
    // 添加选项卡对应的iframe
    var str1 = '<iframe class="J_iframe" width="100%" height="100%" src="' + url + '" frameborder="0" data-id="' + url + '" seamless></iframe>';
    $(window.parent.document).find('.J_mainContent').find('iframe.J_iframe').hide().parents('.J_mainContent').append(str1);
};

//分页函数
$(function(){
    $('.jump-page-submit').click(function(){
        var url = $('.jump-page').data('url-template').replace('page_num', $('.jump-page').val());
        location.href = url;
    });

    $('.jump-page').keyup(function(){
        var max = $(this).data('max');
        if($(this).val() > max){
            $(this).val(max);
        }else if($(this).val() <= 0){
            $(this).val(1);
        }
    });
});